`
https://leetcode.cn/problems/count-substrings-that-satisfy-k-constraint-i/
`

/**
 * @param {string} s
 * @param {number} k
 * @return {number}
 */
var countKConstraintSubstrings = function (s, k) {
  const n = s.length
  const cnt = new Array(2).fill(0)
  let res = 0
  let left = 0, right = 0

  while (right < n) {
    const n1 = +s[right++]
    cnt[n1]++

    while (cnt[0] > k && cnt[1] > k) {
      const n2 = +s[left++]
      cnt[n2]--
    }

    res += right - left
  }

  return res
};